<style type="text/css">
    .optionul{margin:0px 0px 0px 60px}
    .optionul li{margin:5px 0px}
    .question_info u,.optionul u{text-decoration:none }
    .bot_add{margin:0px 0px 5px 60px}
    .add_questio,{margin:5px 0px}


</style>
<script type="text/javascript">
    /*添加选项*/
    var A = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    function additem(obj)
    {
        var liarr = $(obj).parent().parent().find("ul li");
        if(liarr.length < 9)
        {
            var html=$('textarea[name="itemmodel"]').val();
            $(obj).parent().parent().find("ul").eq(0).append(html);
        }
        else
        {
            alert("亲，选项已经不少多了!");
            return;
        }
        /*
         liarr = $(obj).parent().parent().find("ul li");
         for(var i=0;i<liarr.length;i++)
         {
         liarr.eq(i).find('span').eq(0).html(A[i]);
         }
         */
        var question_box=$(obj).parents('.question_box');
        rebuilderitem(question_box);
    }
    function deleteitem(obj)
    {
        var liarr = $(obj).parents("ul");
        //alert(liarr.find('li').length);
        //return;
        var question_box=$(obj).parents('.question_box');
        if(liarr.find('li').length > 2)
        {
            $(obj).parents("li").remove();
        }
        else
        {
            alert("选项至少二个!");
            return;
        }
        rebuilderitem(question_box);
    }
    function rebuilderitem(question_box)
    {
        //alert(question_box.find("li").length);
        question_box.find("li").each(function() {
            //alert(question_box.html());
            $(this).find('span').eq(0).html(A[$(this).index()]);
            $(this).find('input[class="text input-6x"]').eq(0).attr('name', 'option['+question_box.index()+']['+$(this).index()+']');
        });
    }
    function rebuilder()
    {
        $(".question_box").each(function() {
            //$(this).find("u").html($(this).index());
            //alert($(this).index());
            $(this).find("input[class='text input-large']").attr('name', 'question['+$(this).index()+']');
            $(this).find("input[type='checkbox']").attr('name', 'ismulti['+$(this).index()+']');
            $(this).find("input[type='checkbox']").val($(this).index());
            $(this).find("u").eq(0).html(($(this).index()+1));
            rebuilderitem($(this));
            // $(this).find(".question_info label").attr('for', 'ismulti_'+$(this).index());
            // $(this).find(".question_info .hide_qid").attr('name', 'qid['+$(this).index()+']');
            // $(this).find("ul").attr('id', $(this).index());

        });
    }
    function addquestion(obj)
    {
        if($('.question_box').length<10)
        {
            var html=$('textarea[name="questionmodel"]').val();
            $(".add_questio").before(html);
        }
        else
        {
            alert("亲，选项已经不少多了!");
            return;
        }
        rebuilder();
    }
    function deletequestion(obj)
    {
        if($('.question_box').length > 1)
        {
            $(obj).parents(".question_box").remove();
        }
        else
        {
            alert("选项至少一个!");
            return;
        }
        rebuilder();
    }
    $(function(){
        if($('.question_box').length==0)
        {
            addquestion(null);
        }
    })
</script>
<textarea name="itemmodel" cols="" rows="" style="display:none">
                        <li>
                            <span>{label}</span><u>选项：</u>
                            <input type="text" class="text input-6x" name="option[1][4]" value="">
                            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
                        </li>
                    </textarea>
<textarea name="questionmodel" cols="" rows="" style="display:none">
                    <div class="question_box" id="question_info_1">
                        <p class="question_info">
                            <span>问题<u>1</u>：</span>
                            <input type="text" class="text input-large" name="question[1]" value="">
                            <input type="checkbox" class="checkd" name="ismulti[1]" id="ismulti_1" value="1">
                            <label for="ismulti_1"> 允许多选</label>&nbsp;&nbsp;<a href="javascript:;" class="box_del"  onClick="deletequestion(this)">删除</a>                    </p>
                        <ul id="1" class="optionul">
                            <li>
                                <span>A</span><u>选项：</u>
                                <input type="text" class="text input-6x" name="option[1][0]" value="">
                                <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
                            </li><li>
                            <span>A</span><u>选项：</u>
                            <input type="text" class="text input-6x" name="option[1][1]" value="">
                            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
                        </li><li>
                            <span>A</span><u>选项：</u>
                            <input type="text" class="text input-6x" name="option[1][2]" value="">
                            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
                        </li><li>
                            <span>A</span><u>选项：</u>
                            <input type="text" class="text input-6x" name="option[1][3]" value="">
                            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
                        </li>
                        </ul>
                        <p class="bot_add"><button type="button" class="btn" onClick="additem(this)">再添加一个选项</button></p>
                    </div>
                    </textarea>

<div class="topic_box">
    <!--div class="question_box" id="question_info_1">
    <p class="question_info">
        <span>问题<u>1</u>：</span>
        <input type="text" class="text input-large" name="question[1]" value="">
        <input type="checkbox" class="checkd" name="ismulti[1]" id="ismulti_1" value="1">
        <label for="ismulti_1"> 允许多选</label>&nbsp;&nbsp;<a href="javascript:;" class="box_del"  onClick="deletequestion(this)">删除</a>                    </p>
    <ul id="1" class="optionul">
        <li>
            <span>A</span><u>选项：</u>
            <input type="text" class="text input-6x" name="option[1][1]" value="">
            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
        </li><li>
            <span>A</span><u>选项：</u>
            <input type="text" class="text input-6x" name="option[1][2]" value="">
            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
        </li><li>
            <span>A</span><u>选项：</u>
            <input type="text" class="text input-6x" name="option[1][3]" value="">
            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
        </li><li>
            <span>A</span><u>选项：</u>
            <input type="text" class="text input-6x" name="option[1][4]" value="">
            <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
        </li>
    </ul>
    <p class="bot_add"><button type="button" class="btn" onClick="additem(this)">再添加一个选项</button></p>
</div-->
    <php>
        //dump($field);
        $A = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
        $i=0;
        foreach($field['value'] as $key=>$val)
        {
        //dump($val);
    </php>
    <div class="question_box" id="question_info_1">
        <p class="question_info">
            <span>问题<u>{$i+1}</u>：</span>
            <input type="text" class="text input-large" name="question[{$i}]" value="{$val['name']}">
            <input type="checkbox" class="checkd" name="ismulti[{$i}]" id="ismulti_1" value="{$i}" <php>if($val["type"]=='1'){echo 'checked';}</php>>
            <label for="ismulti_1"> 允许多选</label>&nbsp;&nbsp;<a href="javascript:;" class="box_del"  onClick="deletequestion(this)">删除</a>                    </p>
        <ul id="1" class="optionul">
            <php>
                $j=0;
                foreach($val['answer'] as $_key=>$_val)
                {
            </php>
            <li>
                <span>{$A[$j]}</span><u>选项：</u>
                <input type="text" class="text input-6x" name="option[{$i}][{$j}]" value="{$_val['name']}">
                <a class="list_del" href="javascript:;" title="删除这个选项" onClick="deleteitem(this)">×</a>
            </li>
            <php>
                $j++;
                }
            </php>
        </ul>
        <p class="bot_add"><button type="button" class="btn" onClick="additem(this)">再添加一个选项</button></p>
    </div>
    <php>
        $i++;
        }
    </php>

    <p class="add_questio"><button type="button" class="btn" onClick="addquestion(this)">添加一题</button></p>
</div>